package edu.hit.pact.pgse.bean;

import java.net.InetSocketAddress;

public class RunnableTask implements Comparable<RunnableTask>{
	private TaskPieceProperty taskPieceProperty;
	private InetSocketAddress storeAddr;
	
	public RunnableTask(TaskPieceProperty taskPieceProperty, InetSocketAddress storeAddr) {
		super();
		this.taskPieceProperty = taskPieceProperty;
		this.storeAddr = storeAddr;
	}

	public TaskPieceProperty getTaskPieceProperty() {
		return taskPieceProperty;
	}

	public void setTaskPieceProperty(TaskPieceProperty taskPieceProperty) {
		this.taskPieceProperty = taskPieceProperty;
	}

	public boolean hasAddr(){
		if (storeAddr != null){
			return true;
		}
		return false;
	}

	public InetSocketAddress getStoreAddr() {
		return storeAddr;
	}

	public void setStoreAddr(InetSocketAddress storeAddr) {
		this.storeAddr = storeAddr;
	}

	public int compareTo(RunnableTask runnableTask) {
		
		int originPriority = this.getTaskPieceProperty().getPiece().getPriority();
		int comparePriority = runnableTask.getTaskPieceProperty().getPiece().getPriority();
		
		if (originPriority == comparePriority){
			return 0;
		} else {
			return originPriority < comparePriority ? -1 : 1;
		}
	}
	
}
